<template>
  <div class="hearing-report">
    <crumb />
    <div class="container">
      <div class="box-left">
        <div class="task-name">任务名称：{{reportData.oralName}}</div>
        <div class="task-speak">
          <div class="sub-head">任务要求:</div>
          {{reportData.oralRemark}}
        </div>
        <div class="task-num">答题数量：{{reportData.oralNum}}题</div>
        <div class="task-over-box">
          <div class="head">共有<span>{{reporSuccessData.finishedList?reporSuccessData.finishedList.length:0}}</span>个人完成案例</div><div class="more" @click='moreSkip'>更多<i class="el-icon-arrow-right"></i></div>
          <ul class="img-content">
            <!-- <li class="item" v-for="(item, index) in 18" :key="index">
              <img src="~@/assets/images/home_tx@2x.png" alt=""/>
              <div class="name">{{item}}</div>
            </li> -->
            <li class="item" v-for="(item, index) in reporSuccessData.finishedList" :key="index">
              <img :src="item.headImgUrl" v-if="item.headImgUrl" alt=""/>
              <img src="~@/assets/images/home_tx@2x.png" v-else alt=""/>
              <div class="name">{{item.stuName}}</div>
            </li>
          </ul>
        </div>
      </div>
      <div class="box-right">
        <!-- 训练报告 -->
        <div class="table table-1">
          <div class="table-head">跟读报告 <time>{{reportData.maxCreateTime}}</time></div>
          <div class="table-content">
            <div>
              <div class="circle left">{{reportData.maxduration?reportData.maxduration:'暂无'}}S</div>
              <div class="text">时长</div>
            </div>
            <div>
             <div class="circle center">{{reportData.maxscore?reportData.maxscore:'暂无'}}</div>
             <div class="text">得分</div>
            </div>
            <div>
              <div class="circle right">{{reportData.rank?reportData.rank:'暂无'}}</div>
              <div class="text">排名</div>
            </div>
          </div>
        </div>
        <!-- 答题情况 -->
        <div class="table table-2">
          <div class="table-head">跟读详情情况</div>
          <div class="table-content">
             <el-table border :data="reporInfoData" style="width: 100%">
              <el-table-column align="center" type="index" label="序号" width="80"></el-table-column>
              <el-table-column align="center" prop="resource_oral_content" show-overflow-tooltip label="对话内容"></el-table-column>
              <el-table-column align="center" prop="file_url" label="原音">
                <template slot-scope="scope">
                  <i class="el-icon-video-pause" @click='AudioPause("audio" + scope.$index,scope.$index)' v-if="scope.row.isPlayOk"></i>
                  <i class="el-icon-video-play" @click='AudioPlay("audio" + scope.$index,scope.$index)' v-if="!scope.row.isPlayOk"></i>
                  <audio :src="scope.row.file_url" :ref='"audio"+scope.$index' v-show="false"></audio>
                  <!-- {{row.file_url}}  -->
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { speechReport, speechFinishedList } from '@/api/student/training/speech'
export default {
  name: 'SkillFollowReport',
  data () {
    return {
      reportData: '',
      reporSuccessData: '',
      reporInfoData: [{ resource_oral_content: "I'll pick you up at the airport when you come back from your business trip.", file_url: 'https://zyzhzs.oss-cn-hangzhou.aliyuncs.com/multimedia/yp/2c9025096ed92038016f145968ee01ca.mp3' },
        { resource_oral_content: "I'll pick you up at the airport when you come back from your business trip.", file_url: 'https://zyzhzs.oss-cn-hangzhou.aliyuncs.com/multimedia/yp/2c9025096ed92038016f145968ee01ca.mp3' },
        { resource_oral_content: "I'll pick you up at the airport when you come back from your business trip.", file_url: 'https://zyzhzs.oss-cn-hangzhou.aliyuncs.com/multimedia/yp/2c9025096ed92038016f145968ee01ca.mp3' },
        { resource_oral_content: "I'll pick you up at the airport when you come back from your business trip.", file_url: 'https://zyzhzs.oss-cn-hangzhou.aliyuncs.com/multimedia/yp/2c9025096ed92038016f145968ee01ca.mp3' }]
    }
  },
  mounted () {
    this.speechReport()
    this.speechFinishedList()
  },
  methods: {
    // 口语训练报告
    async speechReport () {
      let res = await speechReport(
        {
          lessonOralBatchId: this.$route.query.lessonOralBatchId
        }
      )
      if (res.code === '200') {
        this.reportData = res.data
        // console.log('=====@', res)
      } else {
        this.$message.error(res.message)
      }
    },
    // 口语评测完成
    async speechFinishedList () {
      let res = await speechFinishedList(
        {
          lessonOralCatalogId: this.$route.query.lessonOralCatalogId,
          resourceOralId: this.$route.query.resourceOralId
        }
      )
      if (res.code === '200') {
        this.reporSuccessData = res.data
        // console.log('=====@12123', res)
      } else {
        this.$message.error(res.message)
      }
    },
    AudioPlay (ref, index) {
      for (const key in this.$refs) {
        if (ref === key) {
          this.$refs[key].play()
          this.$set(this.reporInfoData[index], 'isPlayOk', true)
          // this.tableData[index].isPlayOk = true
        } else {
          this.reporInfoData.forEach((item, indexOne) => {
            if (index !== indexOne) {
              this.$set(this.reporInfoData[indexOne], 'isPlayOk', false)
            };
          })
          this.$refs[key].currentTime = 0
          this.$refs[key].pause()
          // this.$set(this.tableData[index], 'isPlayOk', false)
        }
        this.$refs[key].addEventListener('ended', this.PlayOk(event, key, index), false)
      }
    },
    PlayOk (eventTar, key, index) {
      return (eventAudio) => {
        this.reporInfoData[index].isPlayOk = false
      }
    },
    AudioPause (ref, index) {
      this.$refs[ref].pause()
      this.reporInfoData[index].isPlayOk = false
    },
    moreSkip () {
      this.$router.push({ name: 'skillfollowsuccess',
        query: {
          lessonOralCatalogId: this.$route.query.lessonOralCatalogId,
          resourceOralId: this.$route.query.resourceOralId
        } })
    }
  }
}
</script>

<style lang="scss" scoped>
.hearing-report {
  .container {
    display: flex;
    justify-content: space-between;
    .box-left {
      width: 590px;
      background: #fff;
      padding: 20px;
      .task-name {
        font-size: 16px;
        font-weight: bold;
      }
      .task-speak {
        background: #f5f5f5;
        margin-top: 20px;
        padding: 10px;
        border-radius: 10px 10px 0 0;
        font-size: 14px;
        line-height: 1.5;
        .sub-head {
          color: #009cf6;
          font-weight: bold;
          margin-bottom: 5px;
        }
      }
      .task-num {
        background: #f5f5f5;
        color: #ff905a;
        border-radius: 0 0 10px 10px;
        padding: 0 10px 20px 10px;
        font-size: 14px;
      }
      .task-over-box {
        font-size: 14px;
        position: relative;
        margin-top: 20px;
        .head {
          span {
            color: #ff905a;
          }
        }
        .more {
          position: absolute;
          right: 0;
          top: 0;
          cursor: pointer;
          &:hover {
            color: #009cf6;
          }
        }
        .img-content {
          display: flex;
          flex-wrap: wrap;
          padding: 20px 2px;
          .item {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            border:1px solid blue;
            margin: 10px 5px 35px 5px;
            img{
              width:100%;
              border-radius: 50%;
            }
            div{
              text-align: center;
              padding-top:15px;
            }
          }
        }
      }
    }
    .box-right {
      width: 590px;
      background: #fff;
      padding: 30px 0;
      .table {
        width: 500px;
        border-radius: 10px;
        border: 1px solid #efefef;
        margin: 0 auto;
        overflow: hidden;
        box-sizing: content-box;
        .table-head {
          display: flex;
          justify-content: space-between;
          align-items: center;
          background: #f5f5f5;
          line-height: 50px;
          position: relative;
          padding: 0 20px;
          font-size: 14px;
          time{
            font-size: 12px;
          }
          i {
            position: absolute;
            top: 15px;
            right: 20px;
            font-size: 20px;
            cursor: pointer;
          }
        }
        .table-content {
          background: #fff;
        }
      }
      .table-1 {
        .table-content {
          display: flex;
          justify-content: space-around;
          align-items: center;
          padding: 20px 0;
          .circle {
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
          }
          .left {
            width: 70px;
            height: 70px;
            border: 5px solid #06c280;
          }
          .center {
            width: 80px;
            height: 80px;
            border: 5px solid #009cf6;
            margin:0 20px;
          }
          .right {
            width: 70px;
            height: 70px;
            border: 5px solid #df6733;
          }
          .text {
            text-align: center;
            margin-top: 20px;
          }
        }
      }
      .table-2 {
        margin-top: 30px;
        .list {
          display: flex;
          flex-wrap: wrap;
          padding: 10px 0;
          .item {
            width: 40px;
            line-height:40px;
            text-align: center;
            border-radius: 50%;
            color: #fff;
            margin: 5px;
            cursor: pointer;
          }
          .hook {
            background: #06c280;
          }
          .fork {
            background: #df1263;
          }
        }
      }
    }
  }
  .answer-popup {
    .sec-title {
      font-size: 14px;
      font-weight: bold;
    }
    .sec-content {
      margin: 10px 0 20px 0;
      line-height: 1.4;
    }
    .cont1 {
      .xz {
        label {
          margin: 10px 0;
        }
      }
    }
    .cont2 {
      .xz {
        display: flex;
        justify-content: space-between;
      }
    }
    .cont3 {
      .xz > div {
        margin: 5px 0;
      }
    }
  }
}
</style>
